{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## langchain 大模型的支持情况列表\n",
    "\n",
    "https://python.langchain.com/docs/integrations/llms/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "#! pip install langchain -i https://mirrors.aliyun.com/pypi/simple"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 通义千问\n",
    "\n",
    "* langchain中通义千问的使用\n",
    "\n",
    "https://python.langchain.com/docs/integrations/llms/tongyi\n",
    "\n",
    "\n",
    "* 通义千问key申请方法：\n",
    "\n",
    "https://help.aliyun.com/zh/dashscope/developer-reference/activate-dashscope-and-create-an-api-key"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "#! pip install --upgrade --quiet  dashscope -i https://mirrors.aliyun.com/pypi/simple"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "#! pip install dashscope -i https://mirrors.aliyun.com/pypi/simple"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'你好！有什么我可以帮助你的吗？'"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import os\n",
    "from langchain_community.llms import Tongyi\n",
    "\n",
    "os.environ[\"DASHSCOPE_API_KEY\"] = \"\"\n",
    "\n",
    "llm_tongyi=Tongyi()\n",
    "llm_tongyi.invoke(\"你好\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 星火大模型\n",
    "\n",
    "* 星火大模型的api接口申请地址\n",
    "\n",
    "https://xinghuo.xfyun.cn/sparkapi\n",
    "\n",
    "* langchain中星火大模型的使用\n",
    "\n",
    "https://python.langchain.com/docs/integrations/llms/sparkllm"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "中央人民政府委员会第四次会议决定1949年10月1日为中华人民共和国宣告成立的日子，每年的10月1日为中华人民共和国国庆日。\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "from langchain_community.llms import SparkLLM\n",
    "\n",
    "os.environ[\"IFLYTEK_SPARK_APP_ID\"] = \"\"\n",
    "os.environ[\"IFLYTEK_SPARK_API_KEY\"] = \"\"\n",
    "os.environ[\"IFLYTEK_SPARK_API_SECRET\"] = \"\"\n",
    "\n",
    "llm_spark = SparkLLM()\n",
    "\n",
    "res = llm_spark.invoke(\"中国国庆日是哪一天?\")\n",
    "print(res)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 文心一言\n",
    "\n",
    "* langchain中的文心一言\n",
    "\n",
    "https://python.langchain.com/docs/integrations/llms/baidu_qianfan_endpoint\n",
    "\n",
    "* 文心一言的key申请（收费）\n",
    "\n",
    "https://cloud.baidu.com/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "! pip install qianfan -i https://mirrors.aliyun.com/pypi/simple"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[INFO] [02-26 11:00:52] openapi_requestor.py:316 [t:19592]: requesting llm api endpoint: /chat/eb-instant\n",
      "[INFO] [02-26 11:00:52] oauth.py:207 [t:19592]: trying to refresh access_token for ak `7aSK7b***`\n",
      "[INFO] [02-26 11:00:53] oauth.py:220 [t:19592]: sucessfully refresh access_token\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "中国的国庆日是**10月1日**。这一天是国家一年中最重要的节日，是中华人民共和国中央人民政府纪念全国人民团结统一、检阅军队、庆祝中华人民共和国成立的举国欢庆的日子。\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "\n",
    "from langchain_community.llms import QianfanLLMEndpoint\n",
    "\n",
    "os.environ[\"QIANFAN_AK\"] = \"\"\n",
    "os.environ[\"QIANFAN_SK\"] = \"\"\n",
    "\n",
    "llm_wenxin = QianfanLLMEndpoint()\n",
    "\n",
    "res = llm_wenxin.invoke(\"中国国庆日是哪一天?\")\n",
    "print(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
